package org.example.purchase.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.purchase.domain.PurchaseList;
import org.example.purchase.service.IPurchaseListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购清单Controller
 * 
 * @author ruoyi
 * @date 2024-07-18
 */
@Controller
@RequestMapping("/purchase/purchaseList")
public class PurchaseListController extends BaseController
{
    private String prefix = "purchase/purchaseList";

    @Autowired
    private IPurchaseListService purchaseListService;

    @RequiresPermissions("purchase:purchaseList:view")
    @GetMapping()
    public String purchaseList()
    {
        return prefix + "/purchaseList";
    }

    /**
     * 查询采购清单列表
     */
    @RequiresPermissions("purchase:purchaseList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PurchaseList purchaseList)
    {
        startPage();
        List<PurchaseList> list = purchaseListService.selectPurchaseListList(purchaseList);
        return getDataTable(list);
    }

    /**
     * 导出采购清单列表
     */
    @RequiresPermissions("purchase:purchaseList:export")
    @Log(title = "采购清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PurchaseList purchaseList)
    {
        List<PurchaseList> list = purchaseListService.selectPurchaseListList(purchaseList);
        ExcelUtil<PurchaseList> util = new ExcelUtil<PurchaseList>(PurchaseList.class);
        return util.exportExcel(list, "采购清单数据");
    }

    /**
     * 新增采购清单
     */
    @RequiresPermissions("purchase:purchaseList:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购清单
     */
    @RequiresPermissions("purchase:purchaseList:add")
    @Log(title = "采购清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PurchaseList purchaseList)
    {
        return toAjax(purchaseListService.insertPurchaseList(purchaseList));
    }

    /**
     * 修改采购清单
     */
    @RequiresPermissions("purchase:purchaseList:edit")
    @GetMapping("/edit/{purchaseListId}")
    public String edit(@PathVariable("purchaseListId") Long purchaseListId, ModelMap mmap)
    {
        PurchaseList purchaseList = purchaseListService.selectPurchaseListByPurchaseListId(purchaseListId);
        mmap.put("purchaseList", purchaseList);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购清单
     */
    @RequiresPermissions("purchase:purchaseList:edit")
    @Log(title = "采购清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PurchaseList purchaseList)
    {
        return toAjax(purchaseListService.updatePurchaseList(purchaseList));
    }

    /**
     * 查看详情
     */
    @RequiresPermissions("purchase:purchaseList:detail")
    @GetMapping("/detail/{purchaseListId}")
    public String detail(@PathVariable("purchaseListId") Long purchaseListId, ModelMap mmap)
    {
        PurchaseList purchaseList = purchaseListService.selectPurchaseListByPurchaseListId(purchaseListId);
        mmap.put("purchaseList", purchaseList);
        return prefix + "/detail";
    }
}